﻿/*
 * Copyright (C) 2012, Jesus Requejo <jesus.requejo@gmail.com> 
 * Licensed under Microsoft Public License (Ms-PL)
 * http://www.microsoft.com/en-us/openness/licenses.aspx#MPL
*/

namespace LoaderServiceManager {

   using System;
   using System.Threading;
   using System.Windows.Forms;
   using Infrastructure;

   static class Program {

      private static string appGuid = "EC74A6A5-04EF-45D2-AB5B-042318CCE3E6";

      [STAThread]
      static void Main() {
         using (Mutex mutex = new Mutex(false, appGuid)) {
            if (!mutex.WaitOne(0, false)) {               
               BringRunningInstanceToFront();
               return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
         }
      }


      private static void BringRunningInstanceToFront() {
         string windowName = MagicStrings.ManagerMessageWindowName;
         string message = MagicStrings.BringServiceManagerToFrontMessage;
         Win32WindowMessengerWrapper.SendMessageToWindow(windowName, message);
      }
   }
}

